package com.openbravo.pos.inventory;

import com.openbravo.basic.BasicException;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.SentenceList;
import com.openbravo.data.loader.SerializerRead;
import com.openbravo.data.loader.StaticSentence;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.data.user.EditorRecord;
import com.openbravo.format.Formats;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;

import java.awt.Component;
import java.util.UUID;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.text.Document;

public class AttributeUseEditor extends JPanel
  implements EditorRecord
{
  private AppView paramAppView;//ati
private SentenceList attributesent = new StaticSentence(paramAppView.getSession(), "SELECT ID, NAME FROM ATTRIBUTE ORDER BY NAME", null, new SerializerRead()
  {
    public Object readValues(DataRead paramDataRead)
      throws BasicException
    {
      return new AttributeInfo(paramDataRead.getString(1), paramDataRead.getString(2));
    }
  });
  private ComboBoxValModel attributemodel = new ComboBoxValModel();
  private Object id;
  private Object attuseid;
  private Object insertid;
  private JComboBox jAttribute;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JTextField jLineno;

  public AttributeUseEditor(AppView paramAppView, DirtyManager paramDirtyManager)
  {
    initComponents();
    this.jLineno.getDocument().addDocumentListener(paramDirtyManager);
    this.jAttribute.addActionListener(paramDirtyManager);
  }

  public void setInsertId(String paramString)
  {
    this.insertid = paramString;
  }

  public void activate()
    throws BasicException
  {
    this.attributemodel = new ComboBoxValModel(this.attributesent.list());
    this.jAttribute.setModel(this.attributemodel);
  }

  public void refresh()
  {
  }

  public void writeValueEOF()
  {
    this.id = null;
    this.attuseid = null;
    this.attributemodel.setSelectedKey(null);
    this.jLineno.setText(null);
    this.jAttribute.setEnabled(false);
    this.jLineno.setEnabled(false);
  }

  public void writeValueInsert()
  {
    this.id = UUID.randomUUID().toString();
    this.attuseid = this.insertid;
    this.attributemodel.setSelectedKey(null);
    this.jLineno.setText(null);
    this.jAttribute.setEnabled(true);
    this.jLineno.setEnabled(true);
  }

  public void writeValueEdit(Object paramObject)
  {
    Object[] arrayOfObject = (Object[])(Object[])paramObject;
    this.id = arrayOfObject[0];
    this.attuseid = arrayOfObject[1];
    this.attributemodel.setSelectedKey(arrayOfObject[2]);
    this.jLineno.setText(Formats.INT.formatValue(arrayOfObject[3]));
    this.jAttribute.setEnabled(true);
    this.jLineno.setEnabled(true);
  }

  public void writeValueDelete(Object paramObject)
  {
    Object[] arrayOfObject = (Object[])(Object[])paramObject;
    this.id = arrayOfObject[0];
    this.attuseid = arrayOfObject[1];
    this.attributemodel.setSelectedKey(arrayOfObject[2]);
    this.jLineno.setText(Formats.INT.formatValue(arrayOfObject[3]));
    this.jAttribute.setEnabled(false);
    this.jLineno.setEnabled(false);
  }

  public Component getComponent()
  {
    return this;
  }

  public Object createValue()
    throws BasicException
  {
    Object[] arrayOfObject = new Object[5];
    arrayOfObject[0] = this.id;
    arrayOfObject[1] = this.attuseid;
    arrayOfObject[2] = this.attributemodel.getSelectedKey();
    arrayOfObject[3] = Formats.INT.parseValue(this.jLineno.getText());
    arrayOfObject[4] = this.attributemodel.getSelectedText();
    return arrayOfObject;
  }

  private void initComponents()
  {
    this.jLabel3 = new JLabel();
    this.jLineno = new JTextField();
    this.jLabel4 = new JLabel();
    this.jAttribute = new JComboBox();
    this.jLabel3.setText(AppLocal.getIntString("label.order"));
    this.jLabel4.setText(AppLocal.getIntString("label.attribute"));
    GroupLayout localGroupLayout = new GroupLayout(this);
    setLayout(localGroupLayout);
    localGroupLayout.setHorizontalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addContainerGap().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel3, -2, 125, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jLineno, -2, 80, -2)).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel4, -2, 125, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jAttribute, -2, 170, -2))).addContainerGap(249, 32767)));
    localGroupLayout.setVerticalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addContainerGap().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel3).addComponent(this.jLineno, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel4).addComponent(this.jAttribute, -2, -1, -2)).addContainerGap(273, 32767)));
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.inventory.AttributeUseEditor
 * JD-Core Version:    0.6.0
 */